package com.xan.servlet;

import com.xan.dao.PlayerDAO;
import com.xan.dao.PlayerEntity;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by xueal on 2017/10/19.
 */
//@WebServlet("/player")
public class PlayerServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        //设置响应内容类型
//        resp.setContentType("text/html");
//
//        //设置逻辑实现
//        PrintWriter out = resp.getWriter();
//        out.println("<h1>" + message + "</h1>");

//        PlayerDAO.addPlayer();

        List<PlayerEntity> listPlayer = PlayerDAO.getPlayers();
        req.setAttribute( "list_player", listPlayer);
        req.getRequestDispatcher( "player.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }

    @Override
    public void init() throws ServletException {
        PlayerDAO.getPlayers();
        System.out.println(this.getClass() + ": init");
    }
}
